package org.example.Day12;

import java.lang.reflect.Method;

public class Test3Method {
    public static void main(String[] args) throws Exception{
        //获取Class对象
        Class c = Cat.class;

        //获取类中全部成员方法
        Method[] methods = c.getDeclaredMethods();

        //遍历这个数组中每一个方法
        for(Method method:methods){
            System.out.println(method.getName()+"===>"+method.getParameterCount()+"===>"+method.getReturnType());
        }
        System.out.println("---------------");
        Method run = c.getDeclaredMethod("run");
        //执行run方法
        Cat cat = new Cat();
        run.setAccessible(true);
        Object rs1 = run.invoke(cat);
        System.out.println(rs1);

        System.out.println(run.getName()+"--->"+run.getParameterCount()+"--->"+run.getReturnType());

        //获取private修饰的eat方法
        Method eat = c.getDeclaredMethod("eat",String.class);
        eat.setAccessible(true);
        Object rs2 = eat.invoke(cat,"鱼儿");
        System.out.println(rs2);
        System.out.println(eat.getName()+"--->"+eat.getParameterCount()+"--->"+eat.getReturnType());
    }
}
